package com.duowan.realtime.thrift;

import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TBinaryProtocol.Factory;
import org.apache.thrift.server.TNonblockingServer;
import org.apache.thrift.server.TServer;
import org.apache.thrift.transport.TNonblockingServerSocket;
import org.apache.thrift.transport.TNonblockingServerTransport;
import org.apache.thrift.transport.TTransportException;

public class HelloServiceAsyncServer {
	/**
	 * 启动 Thrift 异步服务器
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		TNonblockingServerTransport serverTransport;
		try {
			serverTransport = new TNonblockingServerSocket(9999);
			Hello.Processor processor = new Hello.Processor(
					new HelloServiceImpl());
			Factory proFactory = new TBinaryProtocol.Factory();
			TNonblockingServer.Args params = new TNonblockingServer.Args(
					serverTransport);
			params.inputProtocolFactory(proFactory);
			params.processor(processor);
			TServer server = new TNonblockingServer(params);
			System.out.println("Start server on port 9999 ...");
			server.serve();
		} catch (TTransportException e) {
			e.printStackTrace();
		}
	}
}
